//
//  PTOtherSendMsg.swift
//  PointTest28
//
//  Created by sc-chen on 2023/6/28.
//

import SwiftUI

struct PTOtherSendMsg: View {
    @State private var phone = ""
    @State private var theme = ""
    @State private var msgContent = ""
    @State private var isMediaMsg = true
    
    @State private var isShowingHUD = false
    @State private var detailTxt = "不支持开发功能"
    
    @State private var isShowingMessageComposer = false
    
    var body: some View {
        ZStack {
            ScrollView {
                VStack {
                    HStack {
                        Text("输入接收电话号码")
                            .padding()
                        Spacer()
                    }
                    TextField("请输入", text: $phone)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Color.gray, lineWidth: 1)
                        )
                        .frame(height: 40)
                    HStack {
                        Text("输入主题")
                            .padding()
                        Spacer()
                    }
                    TextField("请输入", text: $theme)
                        .overlay(
                            RoundedRectangle(cornerRadius: 10)
                                .stroke(Color.gray, lineWidth: 1)
                        )
                        .frame(height: 40)
                    
                    HStack {
                        Text("彩信内容")
                            .padding()
                        Spacer()
                    }
                    TextField("请输入", text: $msgContent)
                        .overlay(
                            RoundedRectangle(cornerRadius: 5)
                                .stroke(Color.gray, lineWidth: 1)
                        )
                        .frame(height: 40)
                    
                    VStack {
                        Button {
                            if phone.isEmpty {
                                showHud(text: "请输入手机号码")
                                return
                            }
                            if theme.isEmpty {
                                showHud(text: "请输入主题")
                                return
                            }
                            if msgContent.isEmpty {
                                showHud(text: "请输入彩信内容")
                                return
                            }
                            self.isShowingMessageComposer.toggle()
                        } label: {
                            Text("调用系统彩信发送")
                                .foregroundColor(.white)
                                .padding()
                                .frame(maxWidth: .infinity)
                                .background(
                                    RoundedRectangle(cornerRadius: 5)
                                        .fill(Color.blue)
                                )
                        }
                        .buttonStyle(.borderless)
                    }.padding(.top,40)
                    
                    VStack {
                        Button {
                            showHud(text: "不支持开发功能")
                        } label: {
                            Text("通过彩信服务器发送")
                                .foregroundColor(.white)
                                .padding()
                                .frame(maxWidth: .infinity,maxHeight: 50)
                                .background(
                                    RoundedRectangle(cornerRadius: 5)
                                        .fill(Color.blue)
                                        .padding(.leading, 20)
                                        .padding(.trailing, 20)
                                )
                        }

                    }.padding(.top,40)
                        .hidden()
                    Spacer()
                }
            }
            PTProgressHud(isPresented: $isShowingHUD, text: $detailTxt)
        }
    }
    
    private func showHud(text: String) {
        isShowingHUD = true
        detailTxt = text
        DispatchQueue.main.asyncAfter(deadline: .now()+2){
            isShowingHUD = false
        }
    }
}

struct PTOtherSendMsg_Previews: PreviewProvider {
    static var previews: some View {
        PTOtherSendMsg()
    }
}
